
from google.appengine.ext import db

class WeaponModel(db.Model):
    name = db.StringProperty(required=True)
    label = db.StringProperty(required=True)
    range = db.IntegerProperty(required=True, choices=[-1, 0, 1, 2, 3, 4, 5])
    traits = db.ListProperty(db.Key, required=True)

class UnitWeaponModel(db.Model):
    ref = db.StringProperty(required=True) # must refer to a WeaponModel
    power = db.StringProperty(required=True)
    range = db.IntegerProperty(required=False, choices=[-1, 0, 1, 2, 3, 4, 5]) # range override
    arc = db.StringProperty(required=False, choices=['F', 'R', 'A', 'T', 'FT'])
    traits = db.ListProperty(db.Key, required=True)

def getUnitWeaponModelKey(ref, power=None, range=None, arc=None, traits=None):
    vals = []
    vals.append(ref)
    if power is not None:
        vals.append(str(power))
    if range is not None:
        vals.append(str(range))
    if arc is not None:
        vals.append(arc)
    if traits is not None:
        traitrefs = []
        for trait in traits:
            traitrefs.append(trait.ref)
        traitrefs = sorted(traitrefs)
        vals = vals + traitrefs
    return "_".join(vals)